#include <stdio.h>

#include <systems.h>
#include <types.h>
#include <gobjs.h>
#include <page.h>
#include <drivers/input/input.h>

extern u32 fb;
extern PAGE *current_page;
extern struct touch_operations *touch_ops;

PAGE *p;

void onClickCommon(void *o)
{
    GOBJ *g = (GOBJ *)o;
#ifdef INPUT_DEVICE_SUPPORT
    InputDeviceLock();
#endif
    PGPushGObjBottom(p, g);
    

    struct list_head *node1, *node2;
    GOBJ_LINK_NODE *link_node;
    OVERLAPPED_GOBJ_LINK_NODE *ol_node;
    
    printf("{%d}-->\n", g->gid);
    list_for_each(node1, &current_page->gobj_link_root) {
        link_node = container_of(node1, GOBJ_LINK_NODE, list);
        printf("[%d]", link_node->gobj->gid);
        list_for_each(node2, &link_node->gobj->overlapped_gobj_list) {
            ol_node = container_of(node2, OVERLAPPED_GOBJ_LINK_NODE, list);
            printf("->(%d)", ol_node->gobj->gid);
        }
        printf("\n");
    }


    g->redraw(g);
#ifdef INPUT_DEVICE_SUPPORT
    InputDeviceUnlock();
#endif
}

int GEntry()
{
    GOBJ *a, *b, *c, *d, *e, *f;
    
    p = PGCreate();
    PGSetBackground(p, 0, pCOLOR_BLACK);
    
    a = CreateGObj(10, 10, 200, 200, pCOLOR_WHITE);
    b = CreateGObj(220, 10, 200, 200, pCOLOR_YELLOW);
    c = CreateGObj(110, 110, 200, 200, pCOLOR_RED);
    d = CreateGObj(160, 160, 200, 200, pCOLOR_BLUE);
    e = CreateGObj(210, 210, 200, 200, pCOLOR_GREEN);
    f = CreateGObj(260, 260, 200, 200, pCOLOR_OCEAN);
    
    a->onClick = onClickCommon;
    b->onClick = onClickCommon;
    c->onClick = onClickCommon;
    d->onClick = onClickCommon;
    e->onClick = onClickCommon;
    f->onClick = onClickCommon;
    
    PGAddGObj(p, a);
    PGAddGObj(p, b);
    PGAddGObj(p, c);
    PGAddGObj(p, d);
    PGAddGObj(p, e);
    PGAddGObj(p, f);
    
    PGDisplay(p);

    return 0;
}

int GExit()
{
    return 0;
}
